<?php
		echo $this->Html->css(array(
			'style.css',
		));
?>
<style>
.affix,.affix-top{top:0px;background-color: #FFF;z-index: 1020;} /*popover 1010;modal 1050;*/
.affix .nav>li>a,.affix-top .nav>li>a{padding: 10px 8px;}
.detail {
	width: 100%;
	padding: 20px 34px 30px;
}
.panel-success > .panel-heading {
    background-color: #dff0d8;
    color: #3c763d;
}
.panel-default {
    opacity: 0.7;
}
.panel-heading {
    border-bottom: 0 none;
	border-radius: 0 0 0 8px;
    box-shadow: 0 8px 2px 0 #c7c7c7;
}
.panel-danger > .panel-heading {
    color: #FFF;
    background-color: #c71c22;
    border-color: #dddddd;    border-radius: 0 0 0 0px;    box-shadow: none;
}
.step-anchor {margin-bottom: 12px;}

button, input, optgroup, select, textarea {
    color: #666;
}
.popover{z-index:0;}
#ui-datepicker-div,ui-datepicker{z-index:100000;}
pre {
    background-color: transparent;
    border:0 none;
}
blockquote { border-left: 2px solid #eee; font-size: 12px; margin: 10px 0 10px; padding: 10px;}
</style>
<div id="project-header">
	<ul class="nav nav-tabs" role="tablist">  
	  <li class="active"><a href="#">Project Information</a></li>
	  {{if $model_item['task_id']}}
	  	<li><a href="{{$this->Html->url('/admin/tasks/view/'.$model_item['task_id'])}}">Task and bid Information</a></li>
	  {{/if}}
	</ul>
	
</div>
<div class="row">
	<div class="col-sm-2">
		<div id="project-steps" style="position:fixed;width:140px;" class="mb20">
				
					<div class="jdt clearfix mt10"><!--jdt1 start-->
						{{loop $step_slugs $key $slug}}
					       		{{if $datainfo['ProjectStep'][$slug]['confirm_status'] }}
					       				<a  class="btn btn-success mb5 display-block textalign-left" href="#p-{{$slug}}">{{$key+1}}. {{Inflector::humanize($slug)}}</a>
					       		{{elseif $datainfo['ProjectStep'][$slug]['start_status'] }}
					       				<a  class="btn btn-primary mb5 display-block textalign-left" href="#p-{{$slug}}">{{$key+1}}. {{Inflector::humanize($slug)}}</a>
					       		{{else}}
					       			<a  class="btn btn-default mb5 display-block textalign-left" href="#p-{{$slug}}">{{$key+1}}. {{Inflector::humanize($slug)}}</a>
					       		{{/if}}
						{{/loop}}
				     </div>
	      		<!-- <ul class="nav nav-tabs" role="tablist" style="margin-top:0px;">
	      			{{loop $step_slugs $slug}}
					  <li><a href="#p-{{$slug}}">{{Inflector::humanize($slug)}}</a></li>
					{{/loop}}
				</ul>
	      		<ul class="nav nav-tabs" role="tablist" style="margin-top:0px;">
					{{loop $step_slugs $slug}}
					  <li><a href="#p-{{$slug}}">{{Inflector::humanize($slug)}}</a></li>
					{{/loop}}
				</ul> -->
		</div>
	</div>
	<div class="col-sm-10">
	
	
		<div id="project-main">
			
			<h3 class="name" id="p-requirement">{{$model_item['name']}}
				{{$this->Html->link('<i class="glyphicon glyphicon-edit"></i> '.__('Edit'), 
										'/admin/projects/edit/'.$model_item['id'], 
										array('class'=>'btn btn-primary pull-right','target'=>'_blank','escape'=>false)
									);
								}}
			</h3>
			
			<div class="mt20">
						<table class="table table-striped table-noborder">
							<tr>
								<td style="width:240px;">
								<strong>{{__('Time period')}}:</strong> {{$model_item['start_date']}}~{{$model_item['end_date']}}
								</td>
								<td style="width:180px;">
								<strong>{{__('Budget')}}:</strong> <span class="color-orange">{{$model_item['price_des']}}</span>
								</td>
								</tr>
								<tr>
								<td colspan="4">
									<p>
										<strong>{{lang('Company')}}:</strong> 
										<a target="_blank" href="{{$this->Html->url('/admin/customers/view/'.$datainfo['Customer']['id'])}}">{{$datainfo['Customer']['name']}}</a>
									</p>
									
									<p><strong>Email:</strong> {{$datainfo['Customer']['email']}} <strong class="ml30">Telephone:</strong> {{$datainfo['Customer']['telephone']}}</p>
									<p><strong>Website:</strong> {{$datainfo['Customer']['website']}} <strong class="ml30">Address:</strong> {{$datainfo['Customer']['address']}}</p>
								</td>
								</tr>
								<tr>
								<td colspan="4">
								<strong>Project Description: </strong>
									<div id="content-simple">{{substr(strip_tags($model_item['content']),0,200)}} <br/><a href="#p-requirement" onclick="$('#content-full,#content-simple').toggleClass('hidden');">{{__('Read more')}}</a></div>
									<pre id="content-full" class="hidden">{{$model_item['content']}} <br/><a href="#p-requirement" onclick="$('#content-full,#content-simple').toggleClass('hidden');">{{__('Collapse ')}}</a></pre>
								</td>
								</tr>
								<tr><td colspan="4">
									{{lang('contacts')}}: 			
									{{loop $datainfo['Contact'] $contact}}
										<a href="{{$this->Html->url('/admin/contacts/view/'.$contact['id'])}}" target="_blank">{{$contact['name']}}&nbsp;{{$contact['last_name']}}</a> &nbsp;,&nbsp; 
									{{/loop}}
								</td></tr>
								
								<tr><td colspan="4">
									<div class="row">
									{{loop $datainfo['Uploadfile'] $file}}
										<div class="col-sm-3">
										{{if strpos($file['type'],'image')!==false}}
											<a href="/admin/uploadfiles/download/{{$file['id']}}" target="_blank"><img src="{{$file['thumb']}}"/></a>
											<!--<a href="/uploadfiles/download/{{$file['id']}}" class="btn btn-default" target="_blank">{{$file['name']}}</a> -->
										{{else}}
											<a href="/admin/uploadfiles/download/{{$file['id']}}" class="btn btn-default" target="_blank">{{$file['name']}}</a>
										{{/if}}
										</div>
									{{/loop}}
									</div>		
								</td></tr>
								</table>

<div class="clearfix">

	<input type="button" class="btn pull-right btn-warning btn-sm"  data-toggle="modal" data-target="#myModal" value="{{__('Generate order')}}">

	<input type="button" class="btn pull-right btn-primary btn-sm" style="margin-right:15px;"  data-toggle="modal" data-target="#myModal-steps" value="{{__('Add steps')}}">
	

</div>
		<p><br/></p>						
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">{{__('Generate order')}}</h4>
      </div>
      <div class="modal-body">
      		<form action="{{$this->Html->url('/admin/projects/add_order')}}">
						<div class="form-group">
							{{__('Order name')}}：<input type="text" class="form-control" name="data[Order][name]"><br>
							{{__('Pay money')}}：<input type="number" class="form-control" name="data[Cart][price]">
							<input type="hidden" name="data[Cart][product_model]" value="Project">
							<input type="hidden" name="data[Cart][product_id]" value="{{$id}}">
							
						</div>
						<div class="form-group">
							<input type="submit" value="{{__('Generate order')}}">
						</div>
					</form>
      </div>
    </div>
  </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal-steps" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">{{__('Add steps')}}</h4>
      </div>
      <div class="modal-body">
      		{{if count($all_steps) !== count($step_slugs) }}
			<form action="{{$this->Html->url('/admin/projects/initstep/'.$id)}}">
				{{__('Project steps')}}：
				<div>
					{{loop $all_steps $s $n}}
						<?php  if(in_array($s,$step_slugs)) continue; ?>
						<label><input type="checkbox" name="steps[]" value="{{$s}}">{{$n}}</label>
					{{/loop}}
				</div>
				<br/>
				<input type="submit" value="{{__('Add steps')}}">
			</form>
			{{/if}}
      </div>
    </div>
  </div>
</div>

<div class="panel panel-danger">
  <div class="panel-heading">
    <h3 class="panel-title">{{__('Related orders')}}</h3>
  </div>
  <div class="panel-body">
    	<table class="table">	
		{{loop $order_list $order}}
			<tr><td>{{$order['Order']['name']}}</td><td>  {{$order['Order']['total_price']}} </td>
			
			<!-- <td> {{$order['Order']['created']}} </td> -->
			
			<td>
				{{if $order['Order']['status'] == 1}}
					<label class="label label-success">{{__('Paid')}}</label>
				{{else}}
					<a href="javascript:void(0);" data-step="requirement" data-id="{{$order['Order']['id']}}" class="btn-order-confirm btn btn-danger btn-sm">{{__('Confirm received')}}</a>
				{{/if}}
			 </td></tr>
		{{/loop}}
		</table>
  </div>
</div>					
					<hr/>
					
					
					{{if !$datainfo['ProjectStep']['requirement']['confirm_status']}}			
						<a href="javascript:void(0);" data-step="requirement" data-id="{{$datainfo['ProjectStep']['requirement']['id']}}" data-pid="{{$model_item['id']}}" class="btn-step-confirm btn btn-danger btn-step-confirm">{{__('Confirm receive prepaid.')}}</a>
					
					{{else}}
						{{if !$datainfo['ProjectStep']['analysis']['start_status']}}
							<div class="alert alert-success">Confirmed the customer payment,we can start the analysis.</div>
						{{/if}}
						{{if empty($taskinfo)}}
							{{if $datainfo['ProjectStep']['analysis']['confirm_status']}}
								<a class="btn btn-warning btn-lg" href="{{$this->Html->url('/admin/tasks/add')}}?project_id={{$model_item['id']}}">{{__('Publish task')}}</a>
							{{else}}
								<!--<a class="btn disabled btn-warning btn-lg">We can publish a task after the requirements analysis is completed and confirmed.</a>-->
							{{/if}}
						{{/if}}
						
						{{if !empty($executelist) && $taskinfo['Task']['status']<3 &&  $taskinfo['Task']['status']>=1}}
									<div class="alert alert-warning" role="alert">
										<p>Customer need to pay all the money before the bid end. Partner can start a task after confirm payed.</p>
									</div>
									<a href="javascript:void(0);" onclick="if(confirm('Are you sure receive the pay and start the task?')) {return ajaxAction('{{$this->Html->url('/admin/projects/start_task/'.$model_item['id'])}}')}" class="btn btn-primary btn-sm">Confirm Pay and start task.</a>
						{{/if}}
						
						{{if $taskinfo['Task']['status']>=3 && !$datainfo['ProjectStep']['task']['start_status']}}
							<div class="alert alert-warning">Wait partner to start the task.</div>
						{{/if}}
						
					{{/if}}
			</div>
			
			{{loop $datainfo['ProjectStep'] $slug $step}}
				<?php if($slug=='requirement') continue;?>
				<div id="p-{{$slug}}" class="step-anchor"> &nbsp;</div>
				<div  class=" mb10 panel {{if $step['confirm_status']}}panel-success{{elseif $step['start_status']}}panel-primary{{else}}panel-default{{/if}}">
				  <div class="panel-heading">
				    <h4 class="panel-title">{{$step['name']}} 
				    {{if $step['slug']!='feedback'}}
				    	{{if $step['start_status']==0}}
				    		<button data-id="{{$step['id']}}"  data-step="{{$slug}}" data-pid="{{$step['project_id']}}" class="btn btn-primary btn-sm btn-step-start">{{__('Set start')}}</button>
				    	{{elseif $step['finish_status']==0}}
				    		<button data-id="{{$step['id']}}" data-step="{{$slug}}" data-pid="{{$step['project_id']}}" class="btn btn-warning btn-sm btn-step-finish">{{__('Set finish')}}</button>
				    	{{elseif $step['confirm_status']==0}}
				    		<button class="btn btn-warning btn-sm" disabled>{{__('Wait customer confirm')}}</button>
				    	{{else}}
				    		<button class="btn btn-success btn-sm" disabled><i class="glyphicon glyphicon-ok"></i> {{__('Customer confirmed')}}</button>
				    	{{/if}}
				    {{/if}}
					{{$this->Html->link('<i class="glyphicon glyphicon-comment"></i> '.lang('add comment'), 
											'javascript:void(0);', 
											array('data-id'=>$step['id'],'class'=>'btn-add-comment btn btn-primary  btn-sm pull-right','escape'=>false)
										);
									}}</h4>
				  </div>
				  <div class="panel-body">
				  	
				  	{{if $step['slug']!='feedback'}}
				  	<div>
				  		{{$this->MForm->create('ProjectStep',array(
							'class'=>'form-horizontal',
							'role'=>"form",
							'url' => '/admin/project_steps/edit',
							
						))}}
				  			<div class="form-group form-inline">
								<label class="col-sm-2 txt-left" for="ProjectPriceDes">{{__('Plan time')}}</label>
								<div class="col-sm-10 controls">
									{{$this->MForm->hidden('id',array('value'=>$step['id']))}}
									start: {{$this->MForm->input('plan_start',array('label'=>false,'value'=>$step['plan_start']?date('Y-m-d',$step['plan_start']):'','id'=>'p-start-'.$step['id'],'type'=>'text','style'=>'width:150px;','div'=>false,'class'=>'form-control form-datepicker'))}}
									end: {{$this->MForm->input('plan_end',array('label'=>false,'value'=>$step['plan_end']?date('Y-m-d',$step['plan_end']):'','id'=>'p-end-'.$step['id'],'type'=>'text','style'=>'width:150px;','div'=>false,'class'=>'form-control form-datepicker'))}}
									<input class="btn btn-primary" type="submit" value="{{__('Setting')}}">
								</div>
							</div>
							<!-- <div class="form-group form-inline">
								<label class="col-sm-2 txt-left" for="ProjectPriceDes">{{__('Real time')}}</label>
								<div class="col-sm-10 controls">
									start: {{$this->Form->input('real_start',array('label'=>false,'type'=>'text','div'=>false,'class'=>'form-control datepicker'))}}
									end: {{$this->Form->input('real_end',array('label'=>false,'type'=>'text','div'=>false,'class'=>'form-control datepicker'))}}
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-2 txt-left"></label>
								<div class="col-sm-10"><input class="btn btn-primary" type="submit" value="{{__('Setting')}}"></div>
							</div>	 -->			
				  		{{$this->MForm->end()}}
				  		<!-- 
				  		{{if $step['real_start']}}<strong>The actual start time</strong>: {{date('Y-m-d H:i:s',$step['real_start'])}} &nbsp;&nbsp;&nbsp;&nbsp; {{/if}}
				  		{{if $step['real_end']}}<strong>The actual finish time</strong>: {{date('Y-m-d H:i:s',$step['real_end'])}} {{/if}}
				  		 -->
				  		{{if $step['start_status']}}
				  		<table class="table">
							<tr style="vertical-align: top;">
								<td width="150px"><strong>{{__('Upload files')}}</strong>:</td>
				                <td class="th">
				                		{{$this->Swfupload->load('step_files',array('modelClass'=>'ProjectStep','file_upload_progress'=>'progress-step-'.$step['id'],'upload_success_handler'=>'upload_multi_file','item_css'=>'col-md-4','with_list_div'=>false,'data_id' => $step['id'],'label'=>false,'isadmin'=>false))}}
				                </td>
				                <td>
				                	<div id="progress-step-{{$step['id']}}" class="pull-left"></div>					                 
				                 </td>
							 </tr>
							 <tr  class="bbline1" style="height:auto;"><td colspan="3" style="padding:0;">
				                <div id="fileuploadinfo_step_files_{{$step['id']}}" class="execute-file-list">
				                	{{loop $step['Uploadfile'] $file}}
				                	<div class="col-md-4 upload-fileitem">
					                  <a target="_blank" title="{{$file['name']}}" href="/admin/uploadfiles/download/{{$file['id']}}" class="btn btn-success ">
					                  	<i class="glyphicon glyphicon-cloud-download"></i>
					                  	<div class="filename">{{$file['name']}}</div>
					                  	<small>{{getHumanFileSize($file['size'])}}</small>
					                  </a>
					                  <i class="glyphicon glyphicon-remove remove" data-id="{{$file['id']}}" title="{{__('Remove this file')}}"></i>
					                </div> 
				                  	{{/loop}}
				                </div>
				             </td>
				             </tr>
						</table>
						{{/if}}
				  	</div>
				  	{{/if}}
					{{if $step['slug']=='analysis'}} <!-- requirement analysis -->
						{{if !empty($taskinfo)}}
							<h4>{{$taskinfo['Task']['name']}}</h4>
							<p>{{$taskinfo['Task']['content']}}</p>
							{{if !empty($taskinfo['Uploadfile'])}}
								<p><strong>Documents:</strong></p>
								<div class="row">
								{{loop $taskinfo['Uploadfile'] $file}}
									<div class="col-sm-6 col-md-4 upload-fileitem">
									{{if strpos($file['type'],'image')!==false}}
										<a class="btn btn-success " title="{{$file['name']}}" href="/uploadfiles/download/{{$file['id']}}" target="_blank">
									                  	<img src="{{$file['thumb']}}"/>
									                  	<div class="filename">{{$file['name']}}</div>
									                  	<small>{{getHumanFileSize($file['size'])}}</small>
									                  </a>
									{{else}}
										<a class="btn btn-success " title="{{$file['name']}}" href="/uploadfiles/download/{{$file['id']}}" target="_blank">
									                  	<i class="glyphicon glyphicon-cloud-download"></i>
									                  	<div class="filename">{{$file['name']}}</div>
									                  	<small>{{getHumanFileSize($file['size'])}}</small>
									                  </a>
									{{/if}}
									</div>
								{{/loop}}
								</div>
							{{/if}}
						{{else}}
							<div class="alert alert-warning">{{__d('project','admin_analysis_tips')}}</div>				  			
						{{/if}}
					{{elseif $step['slug']=='task'}}
						
						  <div class="panel-body">
								{{if !empty($executelist)}}
									
									 <table class="table1">
							                <tbody>
							                <tr>
							                  <td class="th1">Progress:</td>
							                  <td class="th1">{{$step_progress}}%</td>
							                  <td>
							                    <div class="progress nomb">
							                      <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width: {{$step_progress}}%">
							                        <span class="sr-only"></span>
							                      </div>
							                    </div>
							                  </td>
							                </tr>
							              </tbody>
							     </table>
							     <h3 class="bbline1"> Plans</h3>
									{{loop $executelist $execute}}
										
										<div>
											<div class="pull-right"><strong>Time period:</strong> {{$execute['TaskExecute']['start_date']}} ~ {{$execute['TaskExecute']['end_date']}}</div>
										<h4>{{$execute['TaskExecute']['name']}}
											
										</h4>		
										<div>
								                 	<!-- <div class="col-md-6"><strong>progress rate:</strong> Report Solution</div> -->
								             <p>{{$execute['TaskExecute']['content']}}</p>
								        </div>
								        </div>
									{{/loop}}
								{{/if}}
						  </div>					
						
					{{/if}}
					<table class="table">
					      <tbody id="comment-list-{{$step['id']}}">
					    	              
					      </tbody>				              
					     <tr id="load-more-{{$step['id']}}" style="display:none;">
					        <td class="center">
					          <div><a href="javascript:void(0);" data-id="{{$step['id']}}" data-page="2" data-append="append" class="load-more-content more1">read more</a></div>
					        </td>
					     </tr>
					</table>
				  </div>
				</div>
				
			{{/loop}}
			
		</div>

	</div>
</div>
<!-- Modal -->
<div class="modal fade" id="Modal-Project-Comment" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
    	{{$this->Form->create('Comment',array('id'=>'CommentAddForm','action'=>'add','onsubmit'=>'return AddTaskComment(this);','class'=>"cmt-body",'role'=>"form",))}}
	      <div class="modal-header">
	        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
	        <h4 class="modal-title" id="myModalLabel">Add a comment.</h4>
	      </div>
	      <div class="modal-body">
	        			                
				   <div class="form-group">
				   	 {{$this->Form->input('data_id',array('type'=>'hidden','value'=> 0))}}
				   	 {{$this->Form->input('parent_id',array('type'=>'hidden','value'=> 0))}}
				   	 {{$this->Form->input('cate_id',array('type'=>'hidden','value'=> 0))}}
					{{$this->Form->input('type',array('type'=>'hidden','value'=> 'ProjectStep'))}}
				     <textarea id="CommentBody" placeholder="{{lang('Enter your comment here')}}" rows="3" name="data[Comment][body]" class="kuang form-control"></textarea>
				   </div>
	      </div>
	      <div class="modal-footer">
	        <button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button>
	        <button type="submit" id="btn-sumbit-comment" class="btn btn-primary btn-sm">{{lang('submit_comment')}}</button>
	      </div>
      {{$this->Form->end()}}
    </div>
  </div>
</div>
{{$this->Html->script(array(
	'swfupload/swfupload.js',
	'swfupload/swfupload.queue.js',
	'swfupload/swfupload.cookies.js',
	'swfupload/fileprogress.js',
	'swfupload/handlers.js',
))}}

<script>

$(function(){
	$('.btn-add-comment').click(function(){
		var id=$(this).data('id');
		$('#Modal-Project-Comment').find('#CommentDataId').val(id);
		$('#Modal-Project-Comment').find('#CommentParentId').val(0); //new comment		
		$('#Modal-Project-Comment').modal('show');
	});
	
	//$('body').scrollspy({ target: '#project-steps' })
	
	$('.load-more-content').click(function(){
		var page = $(this).data('page');
		loadCommentData('ProjectStep',$(this).data('id'),page);
		$(this).data('page',parseInt(page)+1);
	});
	$(document).on('click','.reply-link',function(){
		var id=$(this).data('id'); //cate_id
		var pid = $(this).data('pid'); //parent_id
		$('#Modal-Project-Comment').find('#CommentDataId').val(id);
		$('#Modal-Project-Comment').find('#CommentParentId').val(pid); //replay comment		
		$('#Modal-Project-Comment').modal('show');
	});
	
	{{loop $datainfo['ProjectStep'] $slug $step}}
		<?php if($slug=='requirement') continue;?>
		loadCommentData('ProjectStep',{{$step['id']}},1);
	{{/loop}}
	
	$('.btn-step-start').click(function(){
		if(!confirm('Make sure the conditions is ok and then start this step?')) { return false;}
		$this = $(this);
		$.ajax({
			async:true,
			type:'post',
			success:function(request, xhr) {
				if(request.success){
					$this.html(request.success).unbind('click');
					window.location.reload();
				}
				else{
					alert(request.error);				
				}
			},
			url:"{{$this->Html->url(array('controller'=>'projects','action'=>'step_start'))}}",
			data:{'step_id':$this.data('id'),'project_id':$this.data('pid')},
			dataType:'json'
		}) ;
	})
	$('.btn-step-finish').click(function(){
		if(!confirm('Make sure the tasks is finish and then finished this step?')) { return false;}
		$this = $(this);
		$.ajax({
			async:true,
			type:'post',
			success:function(request, xhr) {
				if(request.success){
					$this.html(request.success).unbind('click');
					window.location.reload();
				}
				else{
					alert(request.error);				
				}
			},
			url:"{{$this->Html->url(array('controller'=>'projects','action'=>'step_finish'))}}",
			data:{'step_id':$this.data('id'),'project_id':$this.data('pid')},
			dataType:'json'
		});
	});

	$('.btn-order-confirm').click(function(){
		if(!confirm('Make sure the order is paid?')) { return false;}

		var order_id = $(this).data('id');
		var $this = $(this);
		$.ajax({
			async:true,
			type:'get',
			success:function(request, xhr) {
				if(request.success){
					$this.html(request.success).unbind('click');
					window.location.reload();
				}
				else{
					alert(request.error);				
				}
			},
			url:"{{$this->Html->url(array('controller'=>'projects','action'=>'confirm_payment'))}}/"+ order_id ,
			dataType:'json'
		});
	});


	$('.btn-step-confirm').click(function(){
		$this = $(this);
		var step = $this.data('step');		
		if(step == "requirement"){
			if(!confirm('Are you sure received the customer prepaid?')){
				return false;
			}
		}
		
		$.ajax({
			async:true,
			type:'post',
			success:function(request, xhr) {
				if(request.success){
					$this.html(request.success).addClass('btn-success').unbind('click');
					window.location.reload();
				}
				else{
					alert(request.error);				
				}
			},
			url:"{{$this->Html->url(array('controller'=>'projects','action'=>'step_confirm'))}}",
			data:{'step_id':$this.data('id'),'project_id':$this.data('pid')},
			dataType:'json'
		}) ;
	})
	
})
function loadCommentData(model,id,page){
	$.ajax({
		async:true,
		type:'get',
		success:function(request, xhr) {
			for(var i in request){
				showCommentItem(request[i]['Comment'],'#comment-list-'+id,'append');
			}
		},
		url: BASEURL +"/admin/comments/getlist/"+ model +"/"+id+'.json?page='+page,		
		dataType:'json'
	});
}


function showCommentItem(item,tselector,append_type){
	var str = '';
	if(item['user_id'] != {{$project_user_id}}){
		str = '<tr><td><img class="pull-left img-circle" title="'+item['username']+'" style="width:50px;height:50px;" src="'+getAvatarUrl(item['user_id'])+'" onerror="this.src=\'{{$this->Html->url('/img/rs/headshot.jpg')}}\'">'
+'<div class="popover show right pull-left" style="position:relative;margin-left:15px;max-width:70%;width:70%;">'
+'<div class="arrow" style="top:30px;"></div>'
+'<div class="popover-content"><p>'+item['username']+':'+item['body']+'</p>'+ item['created']+'</div></div></td></tr>'
;
	}
	else{
		str = '<tr><td><img class="pull-right img-circle" title="'+item['username']+'"  style="width:50px;height:50px;" src="'+getAvatarUrl(item['user_id'])+'" onerror="this.src=\'{{$this->Html->url('/img/rs/headshot.jpg')}}\'">'
		+'<div class="popover show left pull-right" style="position:relative;margin-right:15px;max-width:70%;width:70%;">'
		+'<div class="arrow" style="top:30px;"></div>'
		+'<div class="popover-content"><p>'+item['username']+':'+item['body']+'</p>'+ item['created']+' &nbsp; <a class="reply-link" data-pid="'+item['id']+'" data-id="'+item['data_id']+'" href="javascript:void(0);">Reply</a>'+'</div></div></td></tr>'
		;
	}
	if(append_type == "append"){
		$(tselector).append(str);
	}
	else{
		$(tselector).prepend(str);
	}
}

function AddTaskComment(form){
	$('#Modal-Project-Comment').find('#btn-sumbit-comment').attr('disabled',true);
	$.ajax({
		async:true,
		type:'post',
		success:function(request, xhr) {
			$('#Modal-Project-Comment').find('#btn-sumbit-comment').removeAttr('disabled');
			$('#Modal-Project-Comment').modal('hide');
			if(request.success){
				//showSuccessMessage(request.success);
				if(request['Comment']){
					showCommentItem(request['Comment'],'#comment-list-'+request['Comment']['data_id']);
					//$('#CommentBody',form).val('');
				}
			}
			else{
				alert(errorinfo);				
			}
		},
		url:"{{$this->Html->url(array('controller'=>'comments','action'=>'add'))}}",
		data:$(form).serialize(),
		dataType:'json'
	}) ;
	return false;
}
//]]>
</script>

{{$this->Html->css(array('bootstrap-datepicker.css'))}}
{{$this->Html->script(array('bootstrap-datepicker.js'))}}
<script type="text/javascript">
$(function(){
	$(document).on('click','.form-datepicker',function(){
		if( !$(this).data('datepicker')){
			$(this).datepicker().datepicker('show');
		}
		else{
			$(this).datepicker('show');
		}
	})
})
</script>